package com.info.zhiduoduo.repository.mapper.partner;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.partner.CommissionFlowDto;
import com.info.zhiduoduo.repository.entity.partner.PartnerAccountflow;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 合伙人账户流水(佣金收入，提现明细) Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2019-06-23
 */
public interface PartnerAccountflowMapper extends BaseMapper<PartnerAccountflow> {

    @Select("select * from zdd_partner_accountflow where partnerid = #{partnerid} order by createtime desc")
    List<PartnerAccountflow> getPartnerAccountFlowByPartnerId(@Param("partnerid") int partnerid);

    @Select(" select paf.flowtype,paf.flow_amount,paf.amounttype,paf.createtime,bro.remark,c.compname " +
            " from zdd_partner_accountflow paf " +
            " left join zdd_partner_brokerage bro on paf.brokerageid=bro.brokerageid " +
            " left join zdd_company c on c.compid = paf.compid " +
            " where paf.partnerid = #{partnerid} " +
            " and if(ISNULL(#{compname}) or #{compname} = '', 1=1, c.compname like '%${compname}%') " +
            " and paf.flow_amount > 0 " +
            " and paf.amounttype in (${amounttype}) " +
            "order by paf.createtime desc")
    List<CommissionFlowDto> getPartnerAccountFlow(@Param("partnerid") int partnerid, @Param("compname") String compname,
                                                  @Param("amounttype") String amounttype);

    @Select("select SUM(flow_amount) from zdd_partner_accountflow " +
            "where partnerid = #{partnerid} " +
            "and if(#{flowtype}=0,1=1,flowtype=#{flowtype})")
    BigDecimal getAccountFlowSum(@Param("partnerid") int partnerid, @Param("flowtype") int flowtype);

}
